using System;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;

namespace MapTestFramework.Common
{
	internal class XmlExtensionNode
	{
		private XmlNode _extension = null;
		private const string _extensionAssemblyNameKey = "AssemblyName";
		private const string _extensionClassNameKey = "ClassName";
		private const string _extensionNamepaceKey = "Namespace";

		public XmlExtensionNode(XmlNode extension)
		{
			_extension = extension;
			return;
		}

		private Assembly Assembly
		{
			get
			{
				return Assembly.Load(AssemblyName);
			}
		}

		private string AssemblyName
		{
			get
			{
				return _extension.Attributes.GetNamedItem(_extensionAssemblyNameKey).Value;
			}
		}

		private string ClassName
		{
			get
			{
				return _extension.Attributes.GetNamedItem(_extensionClassNameKey).Value;
			}
		}

		private string Namespace
		{
			get
			{
				return _extension.Attributes.GetNamedItem(_extensionNamepaceKey).Value;
			}
		}

		public void AddArgument(XsltArgumentList arguments)
		{
			arguments.AddExtensionObject(Namespace, CreateClassInstance());
			return;
		}

		private object CreateClassInstance()
		{
			return this.Assembly.CreateInstance(ClassName);
		}
	}
}
